﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using TeenyGrab.Outputs;
using System.Windows.Forms;
using System.Drawing.Imaging;
using TeenyGrab.Helpers;
using TeenyGrab.Serialization;

namespace TeenyGrab.Windows
{
    /// <summary>
    /// Interaction logic for ConfigureFileOutputWindow.xaml
    /// </summary>
    public partial class ConfigureFileOutputWindow : Window
    {
        private FileOutput fileOutput { get; set; }
        public ConfigureFileOutputWindow(FileOutput fileOutput)
        {
            this.fileOutput = fileOutput;

            InitializeComponent();

            textBoxFolder.Text = fileOutput.FilePath;

            comboBoxFiletype.ItemsSource = new List<ImageFormat>()
            {
                ImageFormat.Bmp,
                ImageFormat.Emf,
                ImageFormat.Exif,
                ImageFormat.Gif,
                ImageFormat.Icon,
                ImageFormat.Jpeg,
                ImageFormat.Png,
                ImageFormat.Tiff,
                ImageFormat.Wmf,
            };
            if (fileOutput.Format != null)
            {
                comboBoxFiletype.SelectedValue = fileOutput.Format.Format;
            }
        }

        private void buttonBrowse_Click(object sender, RoutedEventArgs e)
        {
            var fbd = new FolderBrowserDialog();
            fbd.ShowNewFolderButton = true;
            fbd.SelectedPath = textBoxFolder.Text;
            var result = fbd.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                textBoxFolder.Text = fbd.SelectedPath+"\\";
            }
        }

        private void buttonOK_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            fileOutput.FilePath = textBoxFolder.Text;
            fileOutput.Format = new SerializableImageFormat(comboBoxFiletype.SelectedItem as ImageFormat);
            this.Close();
        }
    }
}
